﻿using Max.Ph5_2009A.NewShopping.Domain;
using Max.Ph5_2009A.NewShopping.DTO;
using Max.Ph5_2009A.NewShopping.EFCore;
using Max.Ph5_2009A.NewShopping.IService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Max.Ph5_2009A.NewShopping.API.Controllers
{
    [Route("system/city")]
    [ApiController]
    public class SystemCityDataController : ControllerBase
    {
        ISystemCityDataService _service;

        public SystemCityDataController(ISystemCityDataService service)
        {
            _service = service;
        }

        /// <summary>
        /// 根据父ID获取数据（用于多级联动）
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        [HttpGet("select")]
        public IActionResult Select(int pid)
        {
            ResponseResultOutputDto dto = new();
            var list = _service.GetCityData(pid);
            dto.Data = list;

            return Ok(dto);
        }

        /// <summary>
        /// 根据父ID获取数据（用于级联选择器）
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Select()
        {
            ResponseResultOutputDto dto = new();

            var list = _service.GetResumateCityData(_service.Select().ToList(),0);
            dto.Data = list;

            return Ok(dto);
        }
    }
}
